package com.xpxrule.strategy;

import com.xpxrule.constant.FieldType;
import com.xpxrule.strategy.field.*;

import java.util.concurrent.ConcurrentHashMap;

/**
 * @version 1.0
 * @Author xiangpengxiang
 * @Date 2025/1/7 17:21
 * @注释
 */
public class FieldTypeStrategyContext {
    private static ConcurrentHashMap<FieldType, FieldTypeStrategy> fieldTypeStrategyMap;

    static {
        fieldTypeStrategyMap = new ConcurrentHashMap<>();
        fieldTypeStrategyMap.put(FieldType.STRING, new StringFieldTypeStrategy());
        fieldTypeStrategyMap.put(FieldType.INTEGER, new IntegerTypeStrategy());
        fieldTypeStrategyMap.put(FieldType.DOUBLE, new DoubleTypeStrategy());
        fieldTypeStrategyMap.put(FieldType.LONG, new LongTypeStrategy());
        fieldTypeStrategyMap.put(FieldType.BOOLEAN, new BooleanTypeStrategy());
        fieldTypeStrategyMap.put(FieldType.DATE, new DateTypeStrategy());
        fieldTypeStrategyMap.put(FieldType.BIG_DECIMAL, new BigDecimalTypeStrategy());
    }

    public static FieldTypeStrategy getFieldTypeStrategy(FieldType fieldType) {
        return fieldTypeStrategyMap.get(fieldType);
    }

    public static FieldTypeStrategy getFieldTypeStrategy(String type) {
        FieldType fieldType = FieldType.getValueTypeByType(type);
        return getFieldTypeStrategy(fieldType);
    }
}
